package container

import (
	"fmt"
	"layouts/component_manager"
	"layouts/types"
	"reflect"
)

type Container struct {
	namingList map[string]interface{}
	mgr *types.Manager
}

type Containerable interface {
	Get() interface{}
}

type Componentable interface {
	Component() (string, reflect.Value)
}

func NewContainer() *Container {
	container := &Container{}
	for _, f := range component_manager.AddToContainerFuncs {
		if err := f(container.mgr); err != nil {
			panic(err)
		}
	}
	return container
}

func (c *Container) Has (itemId string) bool {
	if  _,has := c.namingList[itemId]; has {
		return true
	}
	return false
}

func (c *Container) Add(itemId string, val interface{}) interface{} {
	if c.Has(itemId) {
		return c.Get(itemId)
	}
	c.namingList[itemId] = val
	return val
}

func (c *Container) Get(itemId string) interface{} {
	if c.Has(itemId) {
		return c.namingList[itemId]
	}
	return nil
}

func (c *Container) Info() {
	fmt.Println(c.mgr.TypeRegistry)
	fmt.Println(c.namingList)
}



